#pragma once

#include <QtGui/QApplication>
#include <QtGui/QMainWindow>
#include <QCoreApplication>
#include <QSystemTrayIcon>
#include <QMenu>
#include <memory>

#include "Worker.h"

class QSettings;
class QIcon;


class MainModule : public QMainWindow
{
	Q_OBJECT

public:
	MainModule(QWidget* parent = 0, Qt::WFlags flags = 0);

public:
    void Execute();
	void StartWorker();
	void StopWorker(bool gentle = true);

public slots:
    void OnSuccess();
    void OnFailure();

private slots:
    void Abort();
    void Exit();

private:
    void ShowTrayIcon();
    void HideTrayIcon();

private:
	void CreateTrayIcon(const QIcon& icon, const QString& toolTip);
	void CreateMenuActions();
	void CreateMenu();

private:
    void Quit(bool gentle);

private:
    void WriteDefaultIni(QSettings& ini);
    void Initialize(const QSettings& ini);

private:
    WorkerPtr   _worker;
    QString     _deviceName;

private:
    typedef std::tr1::shared_ptr<QSystemTrayIcon> QSystemTrayIconPtr;
    typedef std::tr1::shared_ptr<QAction> QActionPtr;
    typedef std::tr1::shared_ptr<QMenu> QMenuPtr;

	QSystemTrayIconPtr _trayIcon;
    QMenuPtr		   _trayIconMenu;
	QActionPtr		   _labelAction;
    QActionPtr		   _abortAction;
    QActionPtr		   _quitAction;
};

typedef std::tr1::shared_ptr<MainModule> MainModulePtr;
